<!DOCTYPE HTML>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <title></title>
    <META HTTP-EQUIV="pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
    <META HTTP-EQUIV="expires" CONTENT="0">
    <script type="text/javascript" src="../../js/commonCss.js"></script>
    <link rel="stylesheet" type="text/css" href="../../styles/common.css" />
    <style>
        .btn-top{
            position: absolute;
            right: 8%;
            z-index: 9;
            top:0;
        }
        #totalProfit  tr th:last-child,#totalProfit  tr td:last-child{
            text-align: right;
        }
        #yearProfit table tr th,#yearProfit table tr td{
            text-align: right;
        }
        #yearProfit table tr th:first-child, #yearProfit table tr td:first-child{
            text-align: left;
        }
    </style>
</head>
<body>
<div class="panel panel-default">
    <div class="panel-body">
        <div class="btn-top">
            <button type="button" class="btn btn-success top-back" id="backbtn">返回</button>
        </div>

        <p style="margin-top: 20px">预计总利润</p>
        <table class="table table-bordered" id="totalProfit">
            <tr><th>时间</th><th>预计利润</th></tr>
        </table>
        <div id="yearProfit">

        </div>

    </div>
</div>

<script type="text/javascript" src="../../js/commonJs.js"></script>
<script type="text/javascript" src="../../js/jquery.formHelp.js"></script>
<script type="text/javascript" src="../../js/echarts.min.js"></script>
<script type="text/javascript" src="../../assets/js/bui.js"></script>
<script type="text/javascript" src="../../assets/js/config-min.js"></script>
<script type="text/javascript">
    BUI.use('common/page');
</script>
<script>
    $("#backbtn").click(function () {
        top.topManager.openPage({
            id : getQueryString('parentPageId'),
            isClose : true
        });
    });

    $(function () {
        var projectIds = [];
        var projectId = getQueryString('projectId');
        var projectName = getQueryString('projectName');
        var ProjectTotalCost = getQueryString('ProjectTotalCost');
        var type = getQueryString('type');
        var dataId = getQueryString('dataId');

        projectIds.push(projectId);


        $.ajax({
            type: "POST",
            url: ctx + "/estimate/queryActualProfit",
            data:{
                projectId: projectIds
            },
            success: function(data){
                if(data.code == 200){
                    var value = data.data;
                    //获取时间范围
                    //console.log(value)
                    //预计总利润
                    html = '';
                    var totalvalue = 0;
                    if(JSON.stringify(value.yearTotal) == "{}"){
                        html='<tr><td>-</td><td>-</td></tr>';
                        html+='<tr><td>合计</td><td>-</td></tr>';
                    }else{
                        for(var i in value.yearTotal){
                            totalvalue +=value.yearTotal[i];
                            html+='<tr><td>'+i+'</td><td>'+formatMoney(value.yearTotal[i].toFixed(2))+'</td></tr>';
                        }
                        html+='<tr><td>合计</td><td>'+formatMoney(totalvalue.toFixed(2))+'</td></tr>';
                    }
                    $('#totalProfit').append(html);

                    //XX年预计利润
                    html = '';
                    if(value.yearList.length == 0){
                        html+='<p>暂无数据</p>';
                    }else{
                        for(var a in value.yearList){
                            for(var b in value.yearList[a]){
                                html+='<p>'+b+'年预计利润</p>';
                                html+=' <table class="table table-bordered">' +
                                    '<tr><th>类型</th><th>收入</th><th>成本</th><th>利润</th></tr>' +
                                    '<tr><td>实际</td><td>'+formatMoney(value.yearList[a][b].actualIncome.toFixed(2))+'</td><td>'+formatMoney(value.yearList[a][b].actualCost.toFixed(2))+'</td><td>'+formatMoney((value.yearList[a][b].actualIncome-value.yearList[a][b].actualCost).toFixed(2))+'</td></tr>'+
                                    '</table>'
                            }

                        }
                    }

                    $('#yearProfit').append(html);

                }else{
                    alert(data.msg);
                }
            }
        });

    });
</script>
</body>
</html>